﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMS
{
    public partial class CustomForm : Form
    {
        public CustomForm()
        {
            InitializeComponent();
        }

        private void CustomForm_Load(object sender, EventArgs e)
        {
            Startinit();
        }

        private void Startinit()
        {
            this.radioButton1.Checked = true;            
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {

            Model.Custom cus = new PMS.Model.Custom();
            cus.Id = 0;
            cus.CustomerName = txt_name.Text;
            cus.CustomerType = CusType();
            cus.Tel = txt_tel.Text;
            cus.Mobile = txt_mobile.Text;
            cus.Email = txt_email.Text;
            cus.Address = txt_address.Text;
            cus.Contacts = txt_address.Text;
            cus.CPinYin = txt_PY.Text;
            BLL.Custom bllcus = new PMS.BLL.Custom();
            if (bllcus.Insert(cus))
            {
                MessageBox.Show("添加成功!");
            }
            else
            {
                MessageBox.Show("添加失败");
            }
            //MessageBox.Show(CusType().ToString());

        }
        private short CusType()
        {
            if (radioButton1.Checked)
            {
                return 0;
            }
            else if(radioButton2.Checked)
            {
                return 1;
            }
            else
            {
                return 2;
            }
        }

        private void txt_name_TextChanged(object sender, EventArgs e)
        {
            txt_PY.Text = PMS.Helper.helper.GetPYCode(txt_name.Text);
        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
